// [data-theme=default] {
//   --color-primary: coral;
// }

// [data-theme=light] {
//   --color-primary: red;
// }

// [data-theme=dark]  {
//   --color-primary: orange;
// }

$themes: (
  "default": ( 
    --color-primary: coral,
    --bg-color: #121212,
  ),
  "light": (
    --color-primary: red,
    --bg-color: #ebeaea,
  ),
  "dark": (
    --color-primary: orange,
    --bg-color: #ebeaea,
  )
);

$colors: (
  primary: #ff0000,
  secondary: #00ff00,
  tertiary: #0000ff
);

@each $theme-name, $theme-map in $themes {
  html[data-theme='#{$theme-name}']  {
    @each $key, $value in $theme-map {
      #{$key}: #{$value};
    }
  }
}

// 遍历主题map - https://developer.aliyun.com/article/1346145
@mixin themeify {
  @each $theme-name, $theme-map in $themes {
    // !global 把局部变量强升为全局变量
    $theme-map: $theme-map !global;
    // 判断html的data-theme的属性值  #{}是sass的插值表达式
    // & sass嵌套里的父容器标识   @content是混合器插槽，像vue的slot
    [data-theme="#{$theme-name}"] & {
      @content;
    }
  }
}

// 声明一个根据Key获取颜色的function
@function themed($key) {
  @return map-get($theme-map, $key);
}

// 获取背景颜色 - example
@mixin background_color($color) {
  @include themeify {
    background-color: themed($color);
  }
}
